package pers.karl.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.karl.web.entity.TestBean;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("thyleaf")
public class ThyleafController {

    // 数字：整数、浮点数、BigDecimal

    // 字符串

    // 布尔

    // 日期

    // map

    @RequestMapping("/entity")
    public String entity(Model model) {
        return "entity";
    }

    @RequestMapping("/list")
    public String list(Model model) {

        model.addAttribute("msg", "springboot集成thymeleaf");

        int size = 5;
        List<TestBean> list = new ArrayList<>(size);
        for (int i = 1; i <= size; i++) {

            TestBean testBean = new TestBean();
            testBean.setId("id" + String.format("%05d", i));
            testBean.setAge(i);
            testBean.setMoney(new BigDecimal(i));
            testBean.setStartDate(new Date());

            list.add(testBean);
        }

        model.addAttribute("list", list);
        return "list";
    }

    // 实体类中有其他实体对象/集合



}
